import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 					= $Lazy.load(()=>import('#tp/page/page-container'))
const $cache 				= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '统计时间',		names: ['start_at','end_at'], 	type:'date-range' },
			{ label: '岗位',		name: 'project_id',				type: 'select', loading:true },
			{ label: '检测项目',		name: 'kind_id', 				type: 'select', loading:true },
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
			this.fetch()
		}
	}
	//获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 岗位
			$fn.setRow( forms, 'project_id', await f.getCache({ api:'gang_wei' } ) )
			// 检测项目
			$fn.setRow( forms, 'kind_id', await f.getCache({ api:'project_name' } ) )
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'statistics/labNotCompletedCount',{isIndex:true})
	
	// 表单
	cols = [
		{ title: '岗位', 				dataIndex: 'project_name', 				width:200 },
		{ title: '送检医院', 			dataIndex: 'hosp_name', 				width:150 },
		{ title: '自然项目', 			dataIndex: 'parent_kind_name', 			width:150 },
		{ title: '检测项目名称', 		dataIndex: 'kind_name', 				width:150 },
		{ title: '条码号', 				dataIndex: 'spec_code', 				...$fn.table.spec_code },
		{ title: '姓名', 				dataIndex: 'patient_name', 				...$fn.table.name },
		{ title: '性别', 				dataIndex: 'sex_name', 					...$fn.table.sex },
		{ title: '年龄', 				dataIndex: 'age', 						...$fn.table.age },
		{ title: '接收日期', 			dataIndex: 'created_at', 				...$fn.table.time },
		{ title: '应出报告日期', 		dataIndex: 'report_promise_time', 		...$fn.table.time },
		{ title: '超出应出报告日期', 	dataIndex: 'over_time', 				...$fn.table.time },
	]
	// 操作按钮
	controls = () => {
		return [
			Controls.exports.call(this, 'statistics/labNotCompletedCount'),			// 导出
		]
	}
	
	render(){
		return (
			<>
				<Page title='未出结果的样本统计' controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this,{isIndex:true, isInit:window.isInit }) }
				</Page>
			</>
		)
	}
}

export default Index